package visiopuce.graph;


import java.util.Collections;
import java.util.List;

import org.jfree.data.general.Series;
import org.jfree.util.ObjectUtilities;

/**
 * A series that contains zero, one or many {@link FloatingBar} objects.
 * <P>
 * This class is used as a building block for the {@link FloatingBarSeriesCollection}
 * class that can be used to construct basic FloatingBar charts.
 */
public class FloatingBarSeries extends Series {

    /** Storage for the floatingBars in the series. */
    private List floatingBars;

    /**
     * Constructs a new series with the specified name.
     *
     * @param name  the series name (<code>null</code> not permitted).
     */
    public FloatingBarSeries(String name) {
        super(name);
        this.floatingBars = new java.util.ArrayList();
    }

    /**
     * Adds a floatingBar to the series and sends a
     * {@link org.jfree.data.general.SeriesChangeEvent} to all registered
     * listeners.
     *
     * @param floatingBar  the floatingBar (<code>null</code> not permitted).
     */
    public void add(FloatingBar floatingBar) {
        if (floatingBar == null) {
            throw new IllegalArgumentException("Null 'floatingBar' argument.");
        }
        this.floatingBars.add(floatingBar);
        fireSeriesChanged();
    }

    

    

    /**
     * Returns the number of items in the series.
     *
     * @return The item count.
     */
    public int getItemCount() {
        return this.floatingBars.size();
    }

    /**
     * Returns a floatingBar from the series.
     *
     * @param index  the floatingBar index (zero-based).
     *
     * @return The floatingBar.
     */
    public FloatingBar get(int index) {
        return (FloatingBar) this.floatingBars.get(index);
    }

    /**
     * Returns the floatingBar in the series that has the specified description.
     *
     * @param description  the name (<code>null</code> not permitted).
     *
     * @return The floatingBar (possibly <code>null</code>).
     */
    public FloatingBar get(String description) {
        FloatingBar result = null;
        int count = this.floatingBars.size();
        for (int i = 0; i < count; i++) {
            FloatingBar t = (FloatingBar) this.floatingBars.get(i);
            if (t.getDescription().equals(description)) {
                result = t;
                break;
            }
        }
        return result;
    }

    /**
     * Returns an unmodifialble list of the floatingBars in the series.
     *
     * @return The tasks.
     */
    public List getFloatingBars() {
        return Collections.unmodifiableList(this.floatingBars);
    }

    /**
     * Tests this object for equality with an arbitrary object.
     *
     * @param obj  the object to test against (<code>null</code> permitted).
     *
     * @return A boolean.
     */
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof FloatingBarSeries)) {
            return false;
        }
        if (!super.equals(obj)) {
            return false;
        }
        FloatingBarSeries that = (FloatingBarSeries) obj;
        if (!this.floatingBars.equals(that.floatingBars)) {
            return false;
        }
        return true;
    }

    /**
     * Returns an independent copy of this series.
     *
     * @return A clone of the series.
     *
     * @throws CloneNotSupportedException if there is some problem cloning
     *     the dataset.
     */
    public Object clone() throws CloneNotSupportedException {
        FloatingBarSeries clone = (FloatingBarSeries) super.clone();
        clone.floatingBars = (List) ObjectUtilities.deepClone(this.floatingBars);
        return clone;
    }

}
